<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.1.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="开发时我们可以使用RTT来打印logRTT是SEGGER公司开发的用于嵌入式程序中与用户交互的实时终端。RTT搭配JLink的JLinkRTTViewer软件使用">
<meta property="og:type" content="article">
<meta property="og:title" content="nRF52832开发记录--使用RTT打印调试信息">
<meta property="og:url" content="http://example.com/2020/06/02/nRF52832%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95-RTT/index.html">
<meta property="og:site_name" content="webuildthings">
<meta property="og:description" content="开发时我们可以使用RTT来打印logRTT是SEGGER公司开发的用于嵌入式程序中与用户交互的实时终端。RTT搭配JLink的JLinkRTTViewer软件使用">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/2020/06/02/nRF52832%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95-RTT/sdkLogConfig.png">
<meta property="article:published_time" content="2020-06-02T10:40:23.000Z">
<meta property="article:modified_time" content="2020-09-02T03:31:52.982Z">
<meta property="article:author" content="wusk">
<meta property="article:tag" content="BLE">
<meta property="article:tag" content="Nordic">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/2020/06/02/nRF52832%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95-RTT/sdkLogConfig.png">

<link rel="canonical" href="http://example.com/2020/06/02/nRF52832%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95-RTT/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>nRF52832开发记录--使用RTT打印调试信息 | webuildthings</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">webuildthings</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">遇酒且呵呵 人生能几何</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2020/06/02/nRF52832%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95-RTT/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="wusk">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="webuildthings">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          nRF52832开发记录--使用RTT打印调试信息
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-06-02 18:40:23" itemprop="dateCreated datePublished" datetime="2020-06-02T18:40:23+08:00">2020-06-02</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-09-02 11:31:52" itemprop="dateModified" datetime="2020-09-02T11:31:52+08:00">2020-09-02</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/nRF52832/" itemprop="url" rel="index"><span itemprop="name">nRF52832</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/nRF52832/BLE/" itemprop="url" rel="index"><span itemprop="name">BLE</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>开发时我们可以使用RTT来打印log<br>RTT是SEGGER公司开发的用于嵌入式程序中与用户交互的实时终端。<br>RTT搭配JLink的JLinkRTTViewer软件使用    </p>
<a id="more"></a> 

<h1 id="1-RTT"><a href="#1-RTT" class="headerlink" title="1. RTT"></a>1. RTT</h1><p>将RTT源码移植到工程中即可实现RTT功能<br>RTT源码使用ANSI C标准编写可以移植到任何嵌入式程序中<br>RTT实现了一个简易的<code>printf()</code>函数<code>SEGGER_RTT_Printf()</code>,不需要堆    </p>
<p>RTT源码包含在JLink中,安装完JLink后就带有RTT源码<a target="_blank" rel="noopener" href="https://www.segger.com/downloads/jlink/JLink_Windows.exe">Windows JLink</a>    </p>
<p>源码在JLink安装目录下的<code>Samples/RTT</code>    </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">路径:</span><br><span class="line">c&#x2F;Program Files (x86)&#x2F;SEGGER&#x2F;JLink&#x2F;Samples&#x2F;</span><br><span class="line">├── DCC</span><br><span class="line">├── GDB</span><br><span class="line">├── JFlash</span><br><span class="line">├── JFlashSPI</span><br><span class="line">├── JLink</span><br><span class="line">├── RDI</span><br><span class="line">└── RTT</span><br><span class="line">    └── SEGGER_RTT_V680a.zip</span><br><span class="line"></span><br><span class="line">内容:</span><br><span class="line">SEGGER_RTT_V680a</span><br><span class="line">├── Examples</span><br><span class="line">│   ├── Main_RTT_InputEchoApp.c</span><br><span class="line">│   ├── Main_RTT_MenuApp.c</span><br><span class="line">│   ├── Main_RTT_PrintfTest.c</span><br><span class="line">│   └── Main_RTT_SpeedTestApp.c</span><br><span class="line">├── License.txt</span><br><span class="line">├── README.txt</span><br><span class="line">├── RTT</span><br><span class="line">│   ├── SEGGER_RTT.c</span><br><span class="line">│   ├── SEGGER_RTT.h</span><br><span class="line">│   ├── SEGGER_RTT_ASM_ARMv7M.S</span><br><span class="line">│   ├── SEGGER_RTT_Conf.h</span><br><span class="line">│   └── SEGGER_RTT_printf.c</span><br><span class="line">└── Syscalls</span><br><span class="line">    ├── SEGGER_RTT_Syscalls_GCC.c</span><br><span class="line">    ├── SEGGER_RTT_Syscalls_IAR.c</span><br><span class="line">    ├── SEGGER_RTT_Syscalls_KEIL.c</span><br><span class="line">    └── SEGGER_RTT_Syscalls_SES.c</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<p>RTT非常简洁，无需配置即可使用.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*********************************************************************</span><br><span class="line">*               SEGGER MICROCONTROLLER GmbH &amp; Co KG                  *</span><br><span class="line">*       Solutions for real time microcontroller applications         *</span><br><span class="line">**********************************************************************</span><br><span class="line">*                                                                    *</span><br><span class="line">*       (c) 2014  SEGGER Microcontroller GmbH &amp; Co KG                *</span><br><span class="line">*                                                                    *</span><br><span class="line">*       www.segger.com     Support: support@segger.com               *</span><br><span class="line">*                                                                    *</span><br><span class="line">**********************************************************************</span><br><span class="line"></span><br><span class="line">----------------------------------------------------------------------</span><br><span class="line">File    : RTT.c</span><br><span class="line">Purpose : Simple implementation for output via RTT.</span><br><span class="line">          It can be used with any IDE.</span><br><span class="line">--------  END-OF-HEADER  ---------------------------------------------</span><br><span class="line">*&#x2F;</span><br><span class="line"></span><br><span class="line">#include &quot;SEGGER_RTT.h&quot;</span><br><span class="line"></span><br><span class="line">static void _Delay(int period) &#123;</span><br><span class="line">  int i &#x3D; 100000*period;</span><br><span class="line">  do &#123; ; &#125; while (i--);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int main(void) &#123;</span><br><span class="line">  do &#123;</span><br><span class="line">    SEGGER_RTT_WriteString(0, &quot;Hello World from SEGGER!\r\n&quot;);</span><br><span class="line">    _Delay(100);</span><br><span class="line">  &#125; while (1);</span><br><span class="line">  return 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;*************************** End of file ****************************&#x2F;</span><br></pre></td></tr></table></figure>



<h1 id="2-使用SDK-Log模块"><a href="#2-使用SDK-Log模块" class="headerlink" title="2. 使用SDK Log模块"></a>2. 使用SDK Log模块</h1><p>NRF5 SDK通过nRF_Log模块实现log打印，可支持UART和RTT打印    </p>
<h2 id="2-1-配置"><a href="#2-1-配置" class="headerlink" title="2.1 配置"></a>2.1 配置</h2><p>主要配置    </p>
<ul>
<li><code>NRF_LOG_ENABLED</code>              使能nRF_Log模块</li>
<li><code>NRF_LOG_BACKEND_RTT_ENABLED</code>  使能RTT通道</li>
<li><code>NRF_LOG_BACKEND_UART_ENABLED</code> 使能UART通道</li>
<li><code>NRF_LOG_DEFERRED</code>             立即刷新开关<br>配置如下:<br><img src="sdkLogConfig.png" alt="config"></li>
</ul>
<h2 id="2-2-使用"><a href="#2-2-使用" class="headerlink" title="2.2 使用"></a>2.2 使用</h2><ul>
<li>初始化nRF_Log模块:<code>log_init()</code>     </li>
<li>打印log:<code>NRF_LOG_INFO()</code>     </li>
</ul>
<h1 id="3-参考"><a href="#3-参考" class="headerlink" title="3. 参考"></a>3. 参考</h1><ul>
<li>RTT <a target="_blank" rel="noopener" href="https://www.segger.com/jlink-rtt.html"> https://www.segger.com/jlink-rtt.html</a>    </li>
<li>RTT wiki<a target="_blank" rel="noopener" href="https://wiki.segger.com/RTT"> https://wiki.segger.com/RTT</a></li>
<li>如何调试nRF5 SDK <a target="_blank" rel="noopener" href="https://www.cnblogs.com/iini/p/9279618.html"> https://www.cnblogs.com/iini/p/9279618.html</a></li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/BLE/" rel="tag"><i class="fa fa-tag"></i> BLE</a>
              <a href="/tags/Nordic/" rel="tag"><i class="fa fa-tag"></i> Nordic</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/05/27/nRF52832%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95-NFC%E5%81%9A%E6%99%AE%E9%80%9AIO/" rel="prev" title="nRF52832开发记录--NFC做普通IO">
      <i class="fa fa-chevron-left"></i> nRF52832开发记录--NFC做普通IO
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/06/04/nRF52832%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95-%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%BA%90/" rel="next" title="nRF52832开发记录--学习资源">
      nRF52832开发记录--学习资源 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-RTT"><span class="nav-number">1.</span> <span class="nav-text">1. RTT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-%E4%BD%BF%E7%94%A8SDK-Log%E6%A8%A1%E5%9D%97"><span class="nav-number">2.</span> <span class="nav-text">2. 使用SDK Log模块</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#2-1-%E9%85%8D%E7%BD%AE"><span class="nav-number">2.1.</span> <span class="nav-text">2.1 配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-2-%E4%BD%BF%E7%94%A8"><span class="nav-number">2.2.</span> <span class="nav-text">2.2 使用</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-%E5%8F%82%E8%80%83"><span class="nav-number">3.</span> <span class="nav-text">3. 参考</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">wusk</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">34</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">wusk</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
